package com.airoc.demo.service;

import java.text.SimpleDateFormat;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.airoc.demo.dao.DemoMapper;
import com.airoc.demo.dto.OperDTO;
import com.airoc.demo.entity.Oper;
import com.airoc.demo.entity.User;
import com.airoc.demo.param.ChangePasswordParam;
import com.airoc.demo.param.CreateUserParam;
import com.airoc.demo.param.LoginParam;

@Transactional
@Service
public class UserServiceImpl implements UserService {

	@Autowired
	DemoMapper demoMapper;

	@Override
	public boolean changePassword(String operUser, ChangePasswordParam param) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void createUser(String operUser, CreateUserParam param) {
		User user = new User();
		user.setUserName(param.getUserName());
		user.setUserPass(param.getPassword());
		user.setUserAge(param.getAge());
		user.setUserBirth(param.getBirth());
		demoMapper.insertUser(user);
		
		SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" ); 
		String operData = "userName:\"" + user.getUserName() + "\","
				+ "userPass:\"****\","
				+ "userAge:" + user.getUserAge().toString() + ","
				+ "userBirth:\"" + sdf.format(user.getUserBirth()) + "\"";
		Oper oper = new Oper();
		oper.setUserName(operUser);
		oper.setOperType("创建操作员");
		oper.setOperData(operData);
		demoMapper.insertOper(oper);
	}

	@Override
	public boolean login(LoginParam param) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public List<OperDTO> getOpers(String operUser, String userName) {
		// TODO Auto-generated method stub
		return null;
	}

}
